package com.gdou.crrp.common;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class VerifyAPI {
    public static JSONObject verifyIDCard(String name, String identity) throws Exception{
        String host = "https://idcardcert.market.alicloudapi.com";
        String path = "/idCardCert";
        String method = "GET";
        String appcode = "543e20bd04ec42059eae7a5a41751372";//在阿里云上面购买实名认证2要素接口以后就可以获得
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("idCard", identity);
        querys.put("name", name);

            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //状态码: 200 正常；400 URL无效；401 appCode错误； 403 次数用完； 500 API网管错误
            //将HTTPentity（body）的结果解析成json
            JSONObject verifyJson = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
            //System.out.println("Response的body为：" + verifyJson);
        return verifyJson;
    }
}
